﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls.Charting;
using DIST.LR.ZHJG.Controls.Chart;
using System.Globalization;
using System.Collections.ObjectModel;

namespace DIST.LR.ZHJG.Controls.Chart
{
    public partial class ucLine : UserControl
    {
        public ucLine()
        {
            InitializeComponent();
            LineChartData();
        }
        /// <summary>
        /// 注意事项要求AxisName与XAML中一一对应
        /// barchart
        /// </summary>
        public void LineChartData()
        {
            ObservableCollection<ObservableCollection<lineData>> models = new ObservableCollection<ObservableCollection<lineData>>();
            ObservableCollection<lineData> data1 = new ObservableCollection<lineData>();
            string[] months = CultureInfo.CurrentCulture.DateTimeFormat.AbbreviatedMonthNames;
            data1.Add(new lineData("招拍挂","2012", months[0], 223));
            data1.Add(new lineData("招拍挂", "2012", months[1], 203));
            data1.Add(new lineData("招拍挂", "2012", months[2], 324));
            data1.Add(new lineData("招拍挂", "2012", months[3], 437));
            data1.Add(new lineData("招拍挂", "2012", months[4], 223));
            data1.Add(new lineData("招拍挂", "2012", months[5], 243));
            data1.Add(new lineData("招拍挂", "2012", months[6], 200));
            data1.Add(new lineData("招拍挂", "2012", months[7], 273));
            data1.Add(new lineData("招拍挂", "2012", months[8], 223));
            data1.Add(new lineData("招拍挂", "2012", months[9], 262));
            data1.Add(new lineData("招拍挂", "2012", months[10], 252));
            data1.Add(new lineData("招拍挂", "2012", months[11], 234));

            models.Add(data1);
            ObservableCollection<lineData> data2 = new ObservableCollection<lineData>();
            data2.Add(new lineData("协议出让", "2012", months[0], 116));
            data2.Add(new lineData("协议出让", "2012", months[1], 106));
            data2.Add(new lineData("协议出让", "2012", months[2], 178));
            data2.Add(new lineData("协议出让", "2012", months[3], 406));
            data2.Add(new lineData("协议出让", "2012", months[4], 316));
            data2.Add(new lineData("协议出让", "2012", months[5], 188));
            data2.Add(new lineData("协议出让", "2012", months[6], 114));
            data2.Add(new lineData("协议出让", "2012", months[7], 190));
            data2.Add(new lineData("协议出让", "2012", months[8], 116));
            data2.Add(new lineData("协议出让", "2012", months[9], 167));
            data2.Add(new lineData("协议出让", "2012", months[10], 123));
            data2.Add(new lineData("协议出让", "2012", months[11], 123));
            models.Add(data2);
            ObservableCollection<lineData> data3 = new ObservableCollection<lineData>();
            data3.Add(new lineData("划拨", "2012", months[0], 321));
            data3.Add(new lineData("划拨", "2012", months[1], 301));
            data3.Add(new lineData("划拨", "2012", months[2], 211));
            data3.Add(new lineData("划拨", "2012", months[3], 328));
            data3.Add(new lineData("划拨", "2012", months[4], 374));
            data3.Add(new lineData("划拨", "2012", months[5], 321));
            data3.Add(new lineData("划拨", "2012", months[6], 303));
            data3.Add(new lineData("划拨", "2012", months[7], 300));
            data3.Add(new lineData("划拨", "2012", months[8], 372));
            data3.Add(new lineData("划拨", "2012", months[9], 382));
            data3.Add(new lineData("划拨", "2012", months[10], 345));
            data3.Add(new lineData("划拨", "2012", months[11], 321));
            models.Add(data3);

            InitializeLineChartSeriesMappings(models);
        }
        private void InitializeLineChartSeriesMappings(ObservableCollection<ObservableCollection<lineData>> models)
        {
            SeriesMappingCollection seriesMappings = new SeriesMappingCollection();

            foreach (var t in models)
            {
                if (t.Count == 0) continue;
                SplineSeriesDefinition seriesDefinition1 = CreateLineSeriesDefinition();
                SeriesMapping seriesMapping1 = this.CreateSeriesMapping("Month", seriesDefinition1, "Value", ChartAggregateFunction.None, t, t[0].Gdxs);
                seriesMappings.Add(seriesMapping1);

            }

            this.RadChart1.SeriesMappings = seriesMappings;
        }
        private static SplineSeriesDefinition CreateLineSeriesDefinition()
        {
            SplineSeriesDefinition seriesDefinition1 = new SplineSeriesDefinition();
            seriesDefinition1.ShowItemLabels = true;
            seriesDefinition1.ShowPointMarks = true;
            
            return seriesDefinition1;
        }


        private SeriesMapping CreateSeriesMapping(string product, SeriesDefinition seriesDefinition, string yValueField, ChartAggregateFunction aggFunction, ObservableCollection<lineData> models, string legendfield)
        {
            SeriesMapping result = new SeriesMapping();
            result.LegendLabel = legendfield;
            result.SeriesDefinition = seriesDefinition;
            result.ItemMappings.Add(new ItemMapping(product, DataPointMember.XCategory));
            result.ItemMappings.Add(new ItemMapping(yValueField, DataPointMember.YValue, aggFunction));
            result.ItemMappings.Add(new ItemMapping(legendfield, DataPointMember.LegendLabel, aggFunction));
            result.ItemsSource = models;

            return result;
        }
    }
    public class lineData
    {
        private string _gdxs;
        private string _nf;
        private string _month;
        private double _value;
        //private double _zpgValue;
        //private double _xycrValue;
        // private double _hbValue;
        public lineData(string Gdxs, string Nf, string Month, double Value)
        {
            this._gdxs = Gdxs;
            this._nf = Nf;
            this._month = Month;
            this._value = Value;
            //this._zpgValue = ZPGValue;
            //this._xycrValue = XYCRValue;
            //this._hbValue = HBValue;
        }
        public string Gdxs
        {
            get
            {
                return this._gdxs;
            }
            private set
            {
                this._gdxs = value;
            }
        }
        public string Nf
        {
            get
            {
                return this._nf;
            }
            private set
            {
                this._nf = value;
            }
        }
        public string Month
        {
            get
            {
                return this._month;
            }
            private set
            {
                this._month = value;
            }
        }
        public double Value
        {
            get
            {
                return this._value;
            }
            private set
            {
                this._value = value;
            }
        }
        //public double ZPGValue
        //{
        //    get
        //    {
        //        return this._zpgValue;
        //    }
        //    private set
        //    {
        //        this._zpgValue = value;
        //    }
        //}
        //public double XYCRValue
        //{
        //    get
        //    {
        //        return this._xycrValue;
        //    }
        //    private set
        //    {
        //        this._xycrValue = value;
        //    }
        //}
        //public double HBValue
        //{
        //    get
        //    {
        //        return this._hbValue;
        //    }
        //    private set
        //    {
        //        this._hbValue = value;
        //    }
        //}
    }
}
